/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Vista;

import Controller.Conexion;
import Controller.Producto;
import com.mysql.jdbc.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author Nico
 */
public class ConfirmarVenta extends javax.swing.JDialog {

    private static Statement st;
    private ResultSet rs;
    private ResultSet rs1;
    private ResultSet rs2;
    static int idColor, idTalle;
    static float total,ventaConfirmadaTarjeta,porcentajeAmbos,totalAmbos;
    static float porcentaje;
    static float ventaConfirmada, totalSinProducto,totalTarjeta ,descuentoEfectivo,descuentoTarjeta,
               ventaConfirmadaEfectivo;
    static float descuento, descuentoAmbos, efectivoAmbos, tarjetaAmbos;
    static ArrayList producto = new ArrayList();
    static int j = 5, cantidad, stockActual, stockFinal, id=0, idT;
    static int i = 0, stock = 4, t = 6, pre = 3;
    static String codigo;
    static boolean okMayor, okEntre, okNo;
     static String color, talle;

    public ConfirmarVenta(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        llenarComboTarjeta();
        llenarComboTarjetaAmbos();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        radioEfectivo = new javax.swing.JRadioButton();
        radioTargeta = new javax.swing.JRadioButton();
        jTextField1 = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        comboTarjeta = new javax.swing.JComboBox();
        radioAmbos = new javax.swing.JRadioButton();
        jLabel7 = new javax.swing.JLabel();
        txtDescuentoAmbos = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        txtEfectivoAmbos = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        comboTarjetaAmbos = new javax.swing.JComboBox();
        jButton2 = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        jLabel4.setText("Seleccione el método de pago:");

        radioEfectivo.setText("Efectivo");

        radioTargeta.setText("Tarjeta de crédito");

        jTextField1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextField1KeyTyped(evt);
            }
        });

        jLabel6.setText("Porcentaje de descuento:");

        radioAmbos.setText("Efectivo/Tarjeta de crédito");

        jLabel7.setText("Porcentaje de descuento");

        jLabel8.setText("Efectivo");

        jLabel9.setText("Tarjeta de crédito");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(25, 25, 25)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(radioTargeta)
                            .addComponent(radioEfectivo)
                            .addComponent(radioAmbos)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(63, 63, 63)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel6)
                            .addComponent(comboTarjeta, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7)
                            .addComponent(jLabel8)
                            .addComponent(jLabel9))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtDescuentoAmbos)
                            .addComponent(txtEfectivoAmbos)
                            .addComponent(comboTarjetaAmbos, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jTextField1))))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel4)
                .addGap(18, 18, 18)
                .addComponent(radioEfectivo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(4, 4, 4)
                .addComponent(radioTargeta)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(comboTarjeta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(radioAmbos)
                        .addGap(8, 8, 8)
                        .addComponent(jLabel8))
                    .addComponent(txtEfectivoAmbos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(txtDescuentoAmbos, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(comboTarjetaAmbos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(48, Short.MAX_VALUE))
        );

        jButton2.setText("Confirmar Compra");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton1.setText("Cancelar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
        jLabel2.setText("Total a pagar: $");

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
        jLabel3.setForeground(new java.awt.Color(255, 0, 0));
        jLabel3.setText(Float.toString(total));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(90, 90, 90)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel3)
                        .addGap(0, 100, Short.MAX_VALUE))
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(45, 45, 45)
                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(40, 40, 40))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(14, 14, 14)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addGap(46, 46, 46))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        
        
        // si radio es efectivo
        porcentaje = 0;
        ventaConfirmada = 0;
        if (radioEfectivo.isSelected() && !radioTargeta.isSelected()&& !radioAmbos.isSelected()) {
            
            porcentaje = Float.parseFloat(jTextField1.getText());
            
            ventaConfirmada =calculos(porcentaje);
            guardarVtaEfectivo(ventaConfirmada);

             i = 0;id=0; j = 5; stock =4;  pre =3;
            this.setVisible(false);
           } else if (radioAmbos.isSelected() && !radioEfectivo.isSelected() && !radioTargeta.isSelected()) {
                  totalTarjeta= 0;efectivoAmbos =0;ventaConfirmadaTarjeta=0;
                  ventaConfirmadaEfectivo=0; descuentoEfectivo=0;descuentoTarjeta=0;
              if(comboTarjetaAmbos.getSelectedIndex()== 1){
               Date d = new Date();
               GregorianCalendar cal = new GregorianCalendar();
                cal.setTime(d);
                int dia = cal.get(Calendar.DAY_OF_WEEK);
               if (dia == 5){
                    porcentajeAmbos = 15; 
                  
               descuentoAmbos = Float.parseFloat(txtDescuentoAmbos.getText());
              calculosAmbos(descuentoAmbos, porcentajeAmbos);
                
               }
               else{
                   porcentajeAmbos = 0;
                    
               descuentoAmbos = Float.parseFloat(txtDescuentoAmbos.getText());
             calculosAmbos(descuentoAmbos, porcentajeAmbos);
                
               }
            
      
            guardarVtaAmbos(ventaConfirmadaTarjeta,ventaConfirmadaEfectivo,"Galicia");
            
              i = 0;id=0; j = 5; stock =4;  pre =3;
            }
             else if(comboTarjetaAmbos.getSelectedIndex()== 2){
                  porcentajeAmbos = 15; 
                  
               descuentoAmbos = Float.parseFloat(txtDescuentoAmbos.getText());
               calculosAmbos(descuentoAmbos, porcentajeAmbos);
                guardarVtaAmbos(ventaConfirmadaTarjeta,ventaConfirmadaEfectivo, "Frances");
             

            } else if (comboTarjetaAmbos.getSelectedIndex() == 3) {
                porcentajeAmbos = 15;
                 
                descuentoAmbos = Float.parseFloat(txtDescuentoAmbos.getText());
               calculosAmbos(descuentoAmbos, porcentajeAmbos);
               

                 guardarVtaAmbos(ventaConfirmadaTarjeta,ventaConfirmadaEfectivo, "Los Andes Pass");

                  i = 0;id=0; j = 5; stock =4;  pre =3;

            }

            this.setVisible(false);

              
              
              i = 0;id=0; j = 5; stock =4;  pre =3; descuentoAmbos = 0;
             
             } else if (!radioAmbos.isSelected() && !radioEfectivo.isSelected() && radioTargeta.isSelected()) {
            if(comboTarjeta.getSelectedIndex()== 1){
               Date d = new Date();
               GregorianCalendar cal = new GregorianCalendar();
                cal.setTime(d);
                int dia = cal.get(Calendar.DAY_OF_WEEK);
               if (dia == 5){
                    porcentaje = 15; 
                ventaConfirmada =calculos(porcentaje);
                 i = 0;id=0; j = 5; stock =4;  pre =3;
                
               }
               else{
                   porcentaje = 0;
                ventaConfirmada =calculos(porcentaje);   
                  i = 0;id=0; j = 5; stock =4;  pre =3;
                
               }
            
      
            guardarVtaTarjeta(ventaConfirmada,"Galicia");
            
              i = 0;id=0; j = 5; stock =4;  pre =3;
            }
             else if(comboTarjeta.getSelectedIndex()== 2){
                  porcentaje = 15; 
                ventaConfirmada = calculos(porcentaje);
                guardarVtaTarjeta(ventaConfirmada, "Frances");
             

            } else if (comboTarjeta.getSelectedIndex() == 3) {
                porcentaje = 15;
                ventaConfirmada = calculos(porcentaje);
               

                guardarVtaTarjeta(ventaConfirmada, "Los Andes Pass");

                  i = 0;id=0; j = 5; stock =4;  pre =3;

            }

            this.setVisible(false);

        } else if (radioTargeta.isSelected() && radioEfectivo.isSelected() && radioAmbos.isSelected()) {
            JOptionPane.showMessageDialog(rootPane, "debe seleccionar solamente 1");
        } else if (!radioEfectivo.isSelected() && !radioEfectivo.isSelected()&& !radioAmbos.isSelected()) {
            JOptionPane.showMessageDialog(rootPane, "debe seleccionar uno (targeta o efectivo)");
        }

    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        this.setVisible(false);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jTextField1KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField1KeyTyped
        char car = evt.getKeyChar();
        if (jTextField1.getText().length() >= 8) {
            evt.consume();
        }
        if ((car < '0' || car > '9')) {
            evt.consume();
        }
    }//GEN-LAST:event_jTextField1KeyTyped

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ConfirmarVenta.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ConfirmarVenta.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ConfirmarVenta.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ConfirmarVenta.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the dialog
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                ConfirmarVenta dialog = new ConfirmarVenta(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

     
    public static void relizarVtaSinProdEnStock(Statement st1, int id,String cod, int stockF){
    
        Entity.Producto.updateCantidad(id, stockF);
        
    
    }
    public static void confirmarVta(float vieneTotal, ArrayList product) {
        total = 0;
        total = vieneTotal;
        totalAmbos = vieneTotal;
        producto = product;
        
       
           
    }
    public static void  guardarVtaAmbos(float vieneVentaTarj, float vieneVentaEfect, String tarjeta){
     try {
         System.out.println("entrooo");
                    Controller.Ventas.Guardar(vieneVentaEfect, "Efectivo", "no");
                       // Vista.ControlDeCaja.cargarTabla(ventaConfirmada);
                       // Vista.ControlDeCaja.cargarTabla(ventaConfirmada);
                } catch (ClassNotFoundException ex) {
                    Logger.getLogger(ConfirmarVenta.class.getName()).log(Level.SEVERE, null, ex);
                }
       try {
                    Controller.Ventas.Guardar(vieneVentaTarj, "Tarjeta", tarjeta);
                    
                       // Vista.ControlDeCaja.cargarTabla(ventaConfirmada);
                       // Vista.ControlDeCaja.cargarTabla(ventaConfirmada);
                } catch (ClassNotFoundException ex) {
                    Logger.getLogger(ConfirmarVenta.class.getName()).log(Level.SEVERE, null, ex);
                }
     
    
    }
    public static void guardarVtaEfectivo(float vieneVentaConfirmada){
      try {
                    Controller.Ventas.Guardar(vieneVentaConfirmada, "Efectivo", "no");
                       // Vista.ControlDeCaja.cargarTabla(ventaConfirmada);
                       // Vista.ControlDeCaja.cargarTabla(ventaConfirmada);
                } catch (ClassNotFoundException ex) {
                    Logger.getLogger(ConfirmarVenta.class.getName()).log(Level.SEVERE, null, ex);
                }
    }
       public static void guardarVtaTarjeta(float vieneVentaConfirmada, String tarjeta){
      try {
                    Controller.Ventas.Guardar(vieneVentaConfirmada, "Tarjeta", tarjeta);
                    
                       // Vista.ControlDeCaja.cargarTabla(ventaConfirmada);
                       // Vista.ControlDeCaja.cargarTabla(ventaConfirmada);
                } catch (ClassNotFoundException ex) {
                    Logger.getLogger(ConfirmarVenta.class.getName()).log(Level.SEVERE, null, ex);
                }
    }
    
    public static void llenarComboTarjeta(){
        comboTarjeta.addItem("Seleccione Tarjeta");
        comboTarjeta.addItem("Galicia");
        comboTarjeta.addItem("Francés");
        comboTarjeta.addItem("Los Andes Pass");
        
        
    }
    
      public static void llenarComboTarjetaAmbos(){
        comboTarjetaAmbos.addItem("Seleccione Tarjeta");
        comboTarjetaAmbos.addItem("Galicia");
        comboTarjetaAmbos.addItem("Francés");
        comboTarjetaAmbos.addItem("Los Andes Pass");
        
        
    }
    public  void calculosAmbos(float dsto, float porcentaje){
         System.out.println("productooo" + producto);
        // tomar porcentaje de caja de texto
            
           //System.out.println("largo del array" + producto.size());
            // se recorre el producto array
            while (i <= producto.size() + 1 && j <= producto.size() + 1) {
                //tomamos el codigo del array
                codigo = producto.get(i).toString();
                 //System.out.println("codigo " +codigo);
                //tomamos cantidad del array
                cantidad = (Integer) producto.get(j);
                  //System.out.println("cantidad " +cantidad);
            //tomamos stock actual y stock final para validar cantidad 
                stockActual = (Integer) producto.get(stock);
                stockFinal = stockActual - cantidad;
                idT = (Integer)producto.get(id);
                //System.out.println("codigo" + codigo);
                //System.out.println("stock final " +stockFinal);
                //validamos q estock final sea mayor a 0
                if (stockFinal > 0) {
                   //funcion que sea da porque el stock final es mayor al actual 0 mayor a 5
                    if ((stockFinal > stockActual || stockFinal < 5)) {
                        JOptionPane.showMessageDialog(rootPane, "Te quedan: " + stockFinal + "unidades del producto "
                                );
                      //  JOptionPane.showMessageDialog(rootPane, "Venta Confirmada: " + ventaConfirmada);
                      okEntre = true;
                      relizarVtaSinProdEnStock(st,idT,codigo,stockFinal);
                      //  Producto.updateCantidad(st, codigo, idColor, idTalle, stockFinal);
                    // funcion que se da porque el stock final es mayor al actual o mayor a 5
                    } else if (stockFinal > stockActual || stockFinal > 5) {
                      okMayor = true;
                   // Producto.updateCantidad(st, codigo, idColor, idTalle, stockFinal);
                   relizarVtaSinProdEnStock(st,idT,codigo,stockFinal);
                    }
                
               
                    // funcion que se da si el stock final es menor a 0
                } else if(stockFinal < 0)
                    {
                     JOptionPane.showMessageDialog(rootPane, "No alcanza el stock para la cantidad vendida del producto"
                             + codigo);
                     okNo = false;
                     totalSinProducto = (Float)producto.get(pre) * (Integer)producto.get(j);
                     total = total - totalSinProducto;
                   
                     
                    }
               
               efectivoAmbos = Float.parseFloat(txtEfectivoAmbos.getText());
               
               totalTarjeta=   totalAmbos - efectivoAmbos ;
               descuentoEfectivo = (dsto * efectivoAmbos) / 100;
                descuentoTarjeta = (totalTarjeta * porcentaje) / 100;
               ventaConfirmadaEfectivo = efectivoAmbos - descuentoEfectivo;
               ventaConfirmadaTarjeta = totalTarjeta - descuentoTarjeta;
               System.out.println( "descuentoEfectivo" + descuentoEfectivo + " vent efect" + ventaConfirmadaEfectivo 
                       + " venta tarj" + ventaConfirmadaTarjeta + "dto tarj" + descuentoTarjeta +
                       "total tarjeta" + totalTarjeta);
                 
                i = i + 6;
                j = j + 6;
                pre = pre + 6;
                stock = stock +6;
            }
            //ventaConfirmadaTarjeta =0;ventaConfirmadaEfectivo=0;descuentoEfectivo=0;totalTarjeta=0;
           // efectivoAmbos=0;
    
    }
    public  float calculos(float dsto){
        System.out.println("productooo" + producto);
        // tomar porcentaje de caja de texto
            
           //System.out.println("largo del array" + producto.size());
            // se recorre el producto array
            while (i <= producto.size() + 1 && j <= producto.size() + 1) {
                //tomamos el codigo del array
                codigo = producto.get(i).toString();
                 //System.out.println("codigo " +codigo);
                //tomamos cantidad del array
                cantidad = (Integer) producto.get(j);
                  //System.out.println("cantidad " +cantidad);
            //tomamos stock actual y stock final para validar cantidad 
                stockActual = (Integer) producto.get(stock);
                stockFinal = stockActual - cantidad;
                idT = (Integer)producto.get(id);
                //System.out.println("codigo" + codigo);
                //System.out.println("stock final " +stockFinal);
                //validamos q estock final sea mayor a 0
                if (stockFinal > 0) {
                   //funcion que sea da porque el stock final es mayor al actual 0 mayor a 5
                    if ((stockFinal > stockActual || stockFinal < 5)) {
                        JOptionPane.showMessageDialog(rootPane, "Te quedan: " + stockFinal + "unidades del producto "
                                );
                      //  JOptionPane.showMessageDialog(rootPane, "Venta Confirmada: " + ventaConfirmada);
                      okEntre = true;
                      relizarVtaSinProdEnStock(st,idT,codigo,stockFinal);
                      //  Producto.updateCantidad(st, codigo, idColor, idTalle, stockFinal);
                    // funcion que se da porque el stock final es mayor al actual o mayor a 5
                    } else if (stockFinal > stockActual || stockFinal > 5) {
                      okMayor = true;
                   // Producto.updateCantidad(st, codigo, idColor, idTalle, stockFinal);
                   relizarVtaSinProdEnStock(st,idT,codigo,stockFinal);
                    }
                
               
                    // funcion que se da si el stock final es menor a 0
                } else if(stockFinal < 0)
                    {
                     JOptionPane.showMessageDialog(rootPane, "No alcanza el stock para la cantidad vendida del producto"
                             + codigo);
                     okNo = false;
                     totalSinProducto = (Float)producto.get(pre) * (Integer)producto.get(j);
                     total = total - totalSinProducto;
                   
                     
                    }
               descuento = (dsto * total) / 100;
               ventaConfirmada = total - descuento;
           
                 
                i = i + 6;
                j = j + 6;
                pre = pre + 6;
                stock = stock +6;
            }
            return ventaConfirmada;
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private static javax.swing.JComboBox comboTarjeta;
    private static javax.swing.JComboBox comboTarjetaAmbos;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private static javax.swing.JTextField jTextField1;
    private javax.swing.JRadioButton radioAmbos;
    private javax.swing.JRadioButton radioEfectivo;
    private javax.swing.JRadioButton radioTargeta;
    private javax.swing.JTextField txtDescuentoAmbos;
    private javax.swing.JTextField txtEfectivoAmbos;
    // End of variables declaration//GEN-END:variables

  
}
